// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.jasmin.cycletest;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class ProcessingLimitsBenchmark {
  private static final int CYCLES = 3500000 * 2;

  public static void main(String[] args) {
    int a = 3;
    int b = 4;
    int c = 50;
    
    for (int i = CYCLES; i != 0; i--) {
      a = b;
      b += c;
      a = c;
      if (a > 5) {
        b = c - a;
      } else {
        b = c >> 1;
      }
      c = b - a;
      a = b + c;
      b = a >> 5;
      switch (b & 0x03) {
        case 0:
          b = c + a;
          break;
        case 1:
          b = c - a;
          break;
        case 2:
          c = a >> 3;
          break;
        case 3:
          b = c << 2;
          break;
      }
      c = (a + b) << 2;
    }
    
    long time = System.currentTimeMillis();
    for (int i = CYCLES; i != 0; i--) {
      a = b;
      b += c;
      a = c;
      if (a > 5) {
        b = c - a;
      } else {
        b = c >> 1;
      }
      c = b - a;
      a = b + c;
      b = a >> 5;
      switch (b & 0x03) {
        case 0:
          b = c + a;
          break;
        case 1:
          b = c - a;
          break;
        case 2:
          c = a >> 3;
          break;
        case 3:
          b = c << 2;
          break;
      }
      c = (a + b) << 2;
    }
    System.out.println("3.5Mhz in " + (System.currentTimeMillis() - time) + "ms");
  }
}
